package cn.leida.ruoyi.framework.jpa.jpa;

import cn.leida.common.field.bean.JavaFieldBean;
import cn.leida.common.sql.table.bean.JavaTableSqlBean;
import cn.leida.ruoyi.common.core.domain.BaseEntity;
import cn.leida.ruoyi.framework.jpa.tools.JPAJavaFieldUtil;
import lombok.Data;

import java.util.List;

/**
 * @author lei
 * @create 2025-03-11 21:24
 */
@Data
public class JPAJavaTableUtil {


    public static JavaTableSqlBean buildJavaTableSql(Class<?> beanClazz, String tableNameCN) {
        JavaTableSqlBean tableSql = new JavaTableSqlBean();
        // 表名
        tableSql.setTableName(JPAJavaFieldUtil.tableName(beanClazz));
        // 中文表名
        tableSql.setTableNameCN(tableNameCN);
        // id sql 字段: user_id
        tableSql.setTableId(JPAJavaFieldUtil.idSqlField(beanClazz));
        // 排除字段
        if (beanClazz.getSuperclass() == BaseEntity.class) {
            tableSql.excludeJavaFields("searchValue", "params");
        }
        // java属性:
        List<JavaFieldBean> fieldBeans = JPAJavaFieldUtil.jpaJavaFieldBeans(beanClazz);
        tableSql.setFieldBeans(fieldBeans);
        return tableSql;
    }

    public static void printCreateTableSql(Class<?> beanClazz, String tableNameCN) {
        JavaTableSqlBean tableSql = buildJavaTableSql(beanClazz, tableNameCN);
        tableSql.printCreateTableSql();
    }


}
